#include<iostream>
#include<memory>

//类的内部用独占指针
class Girl;
class Boy
{
public:
    Boy()
    {
        std::cout<<"boy构造\n";
    }
    ~Boy()
    {
        std::cout<<"boy析构\n";
    }
    void SetGirl(std::shared_ptr<Girl> &g)
    {
        girlfriend= g;
    }

    private:
    //不会引起计数器的变化
    std::weak_ptr<Girl> girlfriend;
};

class Girl
{
public:
    Girl()
    {
        std::cout<<"Girl构造\n";
    }
    ~Girl()
    {
        std::cout<<"Girl析构\n";
    }
    void Setboy(std::shared_ptr<Boy> &b)
    {
        boyfriend= b;
    }

    private:
    //不会引起计数器的变化
    std::shared_ptr<Boy> boyfriend;
};

int main()
{
    std::shared_ptr<Boy> b= std::make_shared<Boy>();
    std::shared_ptr<Girl> g= std::make_shared<Girl>();

    b->SetGirl(g);
    g->Setboy(b);
    return 0;
}